var commentpostpage=1;
function addformcomment()
{
   $(".wrpTagPlshAddInfoLd").append('<div id="feature'+rowdiv+'" class="itPlg featureclass featurecommentcheck">'+dataform['comment']+"</div>");
   var rownow=rowdiv;


    var rowgnow=1;
  

  
   rowdiv++;
}
function saveformcomment(id,plugid)
{
        var obj={};
        var status=$('input[name="commentstatus[]"]:checked').val();
        var status2=$('input[name="commentstatus2[]"]:checked').val();


        obj={plugid:plugid,status:status,statuscomment:status2};
       
        return obj;
}
function initcommenddata()
{
    $(targetdiv+' .msgcomment').focusout(function() {
          diskeyborad=0;
          
          
          });
          
          
           $(targetdiv+' .msgcomment').focus(function() {
          diskeyborad=1;
          
          
          });

}
function hidepostdata()
{
$(targetdiv+' .commentgroupdata').hide();

}
function nocommendata()
{
$(targetdiv+' .wrpCommentTarget').hide();

}
function getformcomment(dataplugin)
{
var code=''; 

if(dataplugin.nocomment)
{

$(targetdiv+' .wrpCommentTarget').hide();
}else
{
$(targetdiv+' .commentgroupdata').show();
if(dataplugin.nopost)
{
$(targetdiv+' .commentgroupdata').hide();

}


$(targetdiv+' .wrpCommentTarget').show();
$(targetdiv+' .msgcomment').val('');



          $(targetdiv+' .msgcomment').focusout(function() {
          diskeyborad=0;
          
          
          });
          
          
           $(targetdiv+' .msgcomment').focus(function() {
          diskeyborad=1;
          
          
          });

$(targetdiv+' .wrpCommentTarget .addcommentbtn').attr('onclick','savecommentpost('+dataplugin.productid+')'); 

    $(targetdiv+' .wrpCommentTarget .wrpCommentSet').html('');
var textset='Show';
if(dataplugin.comment.length)
{
   $.each(dataplugin.comment, function(key, value) {  
code += '<div class="wrpInCmtLd clBd2 bdBtm" id="commentvalue-'+value['comvid']+'">\n';
code += '<img width="38" height="38" alt="img" src="'+value.userssimg.newpath+'" class="genImgUser imgUserCmtLd">\n';
code += '<div class="cmtLd">\n';


if(roleidinfo==3)
{
textset='Hide';

if(value['status']=='2')
{
textset='Show';
}
code +='<div class="wrpHideCmt" onclick="setdatashowcomment('+value['comvid']+')"><span class="hideCmt fs01 clTxtW clBgBt1">'+textset+' Comment</span></div>';
}

code += '<span class="boldGen userCmtLd clTxt2">'+value.displayname+'</span>\n';
code += '<span class="fs01">'+value.newdate+'</span><br>\n';
code += '<span>'+value.msg+'</span>\n';
code += '</div>\n';
code += '</div>';  







code += '<div class="replyCmt clBg4 clBd2 bdBtm" id="recommentvalue-'+value['comvid']+'">'+"\n";
code += '<div class="wrpInCmtLd clBd2 bdBtm replyCmtInput" >'+"\n";
code += '<img width="38" height="38" alt="img" src="'+$('.imgSBPf').attr('src')+'" class="genImgUser imgUserCmtLd">'+"\n";

code += '<div class="cmtLd clearfix">'+"\n";
code += '<textarea placeholder="Add a Comment" class="fs03 clTxt2 clBg4 clBd2 bdFull mgBtm10"></textarea>'+"\n";
code += '<input type="button" onclick="savecommentpost('+dataplugin.productid+','+value['comvid']+')" value="Reply" class="btnGen btnCmt clTxtW cutTxt clBgSp2 fs04">'+"\n";
code += '</div>'+"\n";

code += '</div>'+"\n";




if(value['reply'].length>0)
{

$.each(value['reply'], function(key2, value2) 
{

code += '<div class="wrpInCmtLd clBd2 bdBtm replydatasetvalue" id="commentvalue-'+value2['comvid']+'">'+"\n";
code += '<img width="38" height="38" alt="img" src="'+value2['userssimg']['newpath']+'" class="genImgUser imgUserCmtLd">'+"\n";
code += '<div class="cmtLd">'+"\n";

if(roleidinfo==3)
{
var text='Hide';

if(value2['status']=='2')
{
var text='Show';
}
code +='<div class="wrpHideCmt" onclick="setdatashowcomment('+value2['comvid']+')"><span class="hideCmt fs01 clTxtW clBgBt1">'+text+' Comment</span></div>';
}


code += '<span class="boldGen userCmtLd clTxt2">'+value2['displayname']+'</span>'+"\n";
code += '<span class="fs01">'+value2['newdate']+'</span><br>'+"\n";
code += '<span>'+value2['msg']+'</span>'+"\n";
code += '</div>'+"\n";
code += '</div>';
});

if(value['reply'].length>19)
{
code += '<button class="btnSeeMore clTxt3 fs02" onclick="loadmorecomment('+value['productid']+','+value['comvid']+')">See More</button>';
}


}


code += '</div>'+"\n";














   });
   
   if(dataplugin.comment.length>19)
{
code+='<button class="btnSeeMore clTxt3 fs02" onclick="loadmorecomment('+dataplugin.productid+')">See More</button>';
}
   
    $(targetdiv+' .wrpCommentTarget .wrpCommentSet').append(code);
    
    
   

   if(useridinfo!='0')
   {
          $(targetdiv+' .wrpCommentTarget .lICmt').show();
          $(targetdiv+' .wrpCommentTarget .noLICmt.clBg4.clBd2.bdFull').hide(); 
          
          

          
          
   }else
   {
           $(targetdiv+' .wrpCommentTarget .lICmt').hide();
           $(targetdiv+' .wrpCommentTarget .noLICmt.clBg4.clBd2.bdFull').show(); 
   
   }
   
   
//   setTimeout('$( "#main-middle .wrpUoutLd .wrpUinLd" ).focus();',1000);     
  // $('.wrpCommentTarget').show(); 

}

}



}
function loadcommentpost(productid,comvid)
{

if(typeof comvid == 'undefined'){
var comvid=0;
}

var pagesetpost=0;
if(comvid==0)  
{
pagesetpost=commentpostpage;

}else
{
pagesetpost=checkarraypage[comvid];


}


var parem=new Array();  
parem[0]=pagesetpost;
parem[1]=productid;
parem[2]=comvid;
$('#main-middle .btnSeeMore').remove();
var code='';
$.post(serviceinfo+"postmedthodplugin",{classset:'comment',medthodset:"getplugincomment",parem:parem},
function(data){

if(data.data.length)
{

var getdata=datamain[productid];
if(typeof  getdata!= "undefined")
{
 var krowset=0;
 if(getdata['plugins'].length>0)
                    {
                    var checkplugins=1;
                   $.each(getdata['plugins'], function(key2, value2) {
                   
                   
                   if(getdata['plugins'][krowset]['plugid']=="17")
                   {
                   
                   getdata['plugins'][krowset]['comment']=data.data;
                   
                   
                   
                   }
                   
                   
                   
                   krowset++;
                   
                   });
                   
                   
                    datamain[productid]['plugins']  =getdata['plugins'];
                    }


//getdata.checkfollow=data.checkfollow;
//getdata.countfollow=data.countfollow;
}





var textset='Show';
var textset2='replydatasetvalue';

        $.each(data.data, function(key, value) {

        
if(comvid==0)  
{
textset2='';

}      
        
code += '<div class="wrpInCmtLd clBd2 bdBtm '+textset2+'" id="commentvalue-'+value['comvid']+'">\n';
code += '<img width="38" height="38" alt="img" src="'+value.userssimg.newpath+'" class="genImgUser imgUserCmtLd">\n';
code += '<div class="cmtLd">\n';

if(roleidinfo==3)
{
textset='Hide';

if(value['status']=='2')
{
textset='Show';
}
code +='<div class="wrpHideCmt" onclick="setdatashowcomment('+value['comvid']+')"><span class="hideCmt fs01 clTxtW clBgBt1">'+textset+' Comment</span></div>';
}


code += '<span class="boldGen userCmtLd clTxt2">'+value.displayname+'</span>\n';
code += '<span class="fs01">'+value.newdate+'</span><br>\n';
code += '<span>'+value.msg+'</span>\n';
if(comvid==0)
{
code +='<p onclick="toggledatareply('+value['comvid']+')" class="replyCmtBtn fs01 clTxt3">reply</p>';
}
code += '</div>\n';
code += '</div>';


if(comvid==0)
{


code += '<div class="replyCmt clBg4 clBd2 bdBtm" id="recommentvalue-'+value['comvid']+'">'+"\n";
code += '<div class="wrpInCmtLd clBd2 bdBtm replyCmtInput" >'+"\n";
code += '<img width="38" height="38" alt="img" src="'+$('.imgSBPf').attr('src')+'" class="genImgUser imgUserCmtLd">'+"\n";

code += '<div class="cmtLd clearfix">'+"\n";
code += '<textarea placeholder="Add a Comment" class="fs03 clTxt2 clBg4 clBd2 bdFull mgBtm10"></textarea>'+"\n";
code += '<input type="button" onclick="savecommentpost('+productid+','+value['comvid']+')" value="Reply" class="btnGen btnCmt clTxtW cutTxt clBgSp2 fs04">'+"\n";
code += '</div>'+"\n";

code += '</div>'+"\n";




if(value['reply'].length>0)
{

$.each(value['reply'], function(key2, value2) 
{

code += '<div class="wrpInCmtLd clBd2 bdBtm replydatasetvalue" id="commentvalue-'+value2['comvid']+'">'+"\n";
code += '<img width="38" height="38" alt="img" src="'+value2['userssimg']['newpath']+'" class="genImgUser imgUserCmtLd">'+"\n";
code += '<div class="cmtLd">'+"\n";

if(roleidinfo==3)
{
var text='Hide';

if(value2['status']=='2')
{
var text='Show';
}
code +='<div class="wrpHideCmt" onclick="setdatashowcomment('+value2['comvid']+')"><span class="hideCmt fs01 clTxtW clBgBt1">'+text+' Comment</span></div>';
}


code += '<span class="boldGen userCmtLd clTxt2">'+value2['displayname']+'</span>'+"\n";
code += '<span class="fs01">'+value2['newdate']+'</span><br>'+"\n";
code += '<span>'+value2['msg']+'</span>'+"\n";
code += '</div>'+"\n";
code += '</div>';
});

if(value['reply'].length>19)
{
code += '<button class="btnSeeMore clTxt3 fs02" onclick="loadmorecomment('+value['productid']+','+value['comvid']+')">See More</button>';
}


}


code += '</div>'+"\n";


}



        });
        
        
}
 


if(data.data.length>19)
{
code+='<button class="btnSeeMore clTxt3 fs02" onclick="loadmorecomment('+productid+','+comvid+')">See More</button>';
}
    if(comvid==0)
{
     $( '#main-middle .wrpCommentSet').append(code);   
}else
{
    if(checkarraypage[comvid]==1)
    {
    $( '#main-middle #recommentvalue-'+comvid+' .replydatasetvalue').remove();
    }
    $( '#main-middle #recommentvalue-'+comvid).append(code);
    


}
     
     loadclosedata();  
     
     
     var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {

}
else
{
$("#main-middle .wrpUinLd").mCustomScrollbar("update");

//setTimeout('rowscrolllanding();',1000);
}
     
});









}
function toggledatareply(comvid)
{

$('#recommentvalue-'+comvid+' .replyCmtInput').toggle();

}
var checkarraypage={};
function loadmorecomment(productid,comvid)
{

if(comvid==0)
{

commentpostpage++;

}else
{
if(typeof checkarraypage[comvid] == 'undefined'){

checkarraypage[comvid]=1;
checkarraypage[comvid]++;

}else
{

checkarraypage[comvid]++;

}



}
loadcommentpost(productid,comvid);


}
function setdatashowcomment(comvid)
{
var parem=new Array();
loaddata(); 
$.post(serviceinfo+"postmedthodplugin",{classset:'comment',medthodset:"showhidecomment",parem:parem,comvid:comvid},
function(data){
loadclosedata(); 
if(data.error.response)
{
  


if(data.error.error[0].code==5)
{
$('.ovlPopLd').hide();
$('.wrpPopLI').fadeIn();

//console.log('test');
}else
{
//alertbox(data.error.error);

alertbox(data.error.error);
}


}
else
{

var textcommentval=$('#commentvalue-'+comvid+' .hideCmt').html();
if(textcommentval=='Hide Comment')
{
$('#commentvalue-'+comvid+' .hideCmt').html('Show Comment');

}else
{

$('#commentvalue-'+comvid+' .hideCmt').html('Hide Comment');

}


}

});

}
function savecommentpost(productid,comvid)
{
if(typeof comvid == 'undefined'){
var comvid=0;


}

var parem=new Array();
//parem[0]=$( '#main-middle .msgcomment').val();
//parem[1]=productid;
var msgdata='';
if(comvid==0)
{

msgdata=$( '#main-middle .msgcomment').val();

}else
{

msgdata=$( '#main-middle #recommentvalue-'+comvid+' textarea').val();

}

if(msgdata)
{loaddata(); 
$.post(serviceinfo+"postmedthodplugin",{classset:'comment',medthodset:"savecomment",comvid:comvid,parem:parem,productid:productid,msg:msgdata},
function(data){
if(data.error.response)
{
loadclosedata();   
if(data.error.error[0].code==5)
{
$('.ovlPopLd').hide();
$('.wrpPopLI').fadeIn();

//console.log('test');
}else
{
//alertbox(data.error.error);

alertbox(data.error.error);
}

}
else
{
if(comvid==0)
{
$( '#main-middle .msgcomment').val('');
$( '#main-middle .wrpCommentSet').html('');
commentpostpage=1;
loadcommentpost(productid,comvid);
}else
{

$( '#main-middle #recommentvalue-'+comvid+' textarea').val('');
if(typeof checkarraypage[comvid] == 'undefined'){

checkarraypage[comvid]=1;

}else
{

checkarraypage[comvid]=1;

}
loadcommentpost(productid,comvid);
}


}


});
}else
{
boxmsgdata('Please Input Msg');

}



}
function editformcomment(datarow)
{
       addformcomment();
       
       var status=$('input[name="commentstatus[]"][value="'+datarow['status']+'"]').attr('checked',true);
       var statuscomment=$('input[name="commentstatus2[]"][value="'+datarow['statuscomment']+'"]').attr('checked',true);
       
       var rownow= rowdiv-1;
       var rowgnow2=1;
       
       



}